package com.chutoutian.controller;

import com.chutoutian.common.Code;
import com.chutoutian.po.Orders;
import com.chutoutian.service.OrdersService;
import com.chutoutian.vo.OrdersVO;
import com.chutoutian.vo.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping(value = "/v1")
public class OrdersController {

    private Logger logger = LoggerFactory.getLogger(OrdersController.class.getName());

    @Resource
    private OrdersService ordersService;

    @GetMapping(value = "/orders/{id}")
    public Object get(@PathVariable("id") String id) {
        Object object = ordersService.get(id);
        return new ResponseMessage.Builder().code(Code.CODE_200).data(object).bulid();
    }

    @PostMapping(value = "/orders")
    public Object add(@RequestBody Orders orders) {
        ordersService.add(orders);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @PutMapping("/orders")
    public Object update(@RequestBody Orders orders) {
        ordersService.update(orders);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @DeleteMapping("/orders/{id}")
    public Object delete(@PathVariable("id") String id) {
        ordersService.delete(id);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @GetMapping("/orders/vo")
    public Object findVO(Orders orders) {
        List<OrdersVO> ordersVOList = ordersService.findVO(orders);
        return new ResponseMessage.Builder().code(Code.CODE_200).data(ordersVOList).bulid();
    }

    @GetMapping("/orders/vo/{id}")
    public Object getVO(@PathVariable("id") String id) {
        OrdersVO ordersVO = ordersService.getVO(id);
        return new ResponseMessage.Builder().code(Code.CODE_200).data(ordersVO).bulid();
    }

}
